package com.hc.controller;

import com.hc.service.JianUserService;
import com.hc.service.NongUserService;
import io.seata.rm.tcc.api.BusinessActionContextUtil;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    NongUserService nongUserService;

    @Autowired
    JianUserService jianUserService;

    @GetMapping("transfer")
    @GlobalTransactional
    public String transfer(int fromId, int toId, double monoey) {
        nongUserService.reduceMoney(BusinessActionContextUtil.getContext(), fromId, monoey);
        jianUserService.incrementMoney(BusinessActionContextUtil.getContext(), toId, monoey);
        return "success";
    }


}
